package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;

import dao.daoAluno;

import modelo.Aluno;

public class DataManager {
	private String dbURL = "";
	private String dbUserName = "";
	private String dbPassword = "";
	public String getDbURL() {
		return dbURL;
	}
	public void setDbURL(String dbURL) {
		this.dbURL = dbURL;
	}
	public String getDbUserName() {
		return dbUserName;
	}
	public void setDbUserName(String dbUserName) {
		this.dbUserName = dbUserName;
	}
	public String getDbPassword() {
		return dbPassword;
	}
	public void setDbPassword(String dbPassword) {
		this.dbPassword = dbPassword;
	}
	
	// returns a connection to the database
	public Connection getConnection() {
	    Connection conn = null;
	    try {
	      conn = DriverManager.getConnection(getDbURL());
	      
	      }
	    catch (SQLException e) {
	    	System.out.println("DataManager");
	      System.out.println("Could not connect to DB: " + e.getMessage());
	      }
	    return conn;
	    } // getConnection
	
	// closes the database connection
	public void putConnection(Connection conn) {
	    if (conn != null) {
	      try { conn.close(); }
	      catch (SQLException e) { }
	      }
	} // putConnection
	
	// Aluno operations
	public ArrayList<Aluno> getAlunos() {
		return daoAluno.getAlunos(this);
	} // getAlunos
}
